package cn.gok.datasource.auto.configure;

import cn.gok.datasource.config.GokMySQLDataSource;
import cn.gok.datasource.factoty.GokMySqlFactory;
import cn.gok.datasource.session.GokSQLSesseion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: chen fan
 * @since: 2022/11/16 17:38
 * @description:  自定义的GokDataSource的  自动装配类
 */
@Configuration
public class GokDataSourceAutoConfigure {

    //第一步： 获取数据源
    @Bean
    public GokMySQLDataSource getGokMySQLDataSource(){
        return new GokMySQLDataSource();
    }

    //创建GokMySqlFactory对象
    @Bean
    public GokMySqlFactory gokMySqlFactory(GokMySQLDataSource getGokMySQLDataSource){
        return new GokMySqlFactory(getGokMySQLDataSource);
    }

    //第三步： 获取GokSQLSesseion对象
    @Bean
    public GokSQLSesseion sqlSesseion(GokMySqlFactory gokMySqlFactory){
        return gokMySqlFactory.openGokSQLSesseion();
    }


}
